﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace Joy.Erp.BasicArchives.Core
{
    public interface IDocumentRepository<TDocument, TDocumentLine, TKey> : IRepository<TDocument, TKey>
        where TDocument : class, IDocumentAggregateRoot<TDocumentLine, TKey>
        where TDocumentLine : class, IDocumentLineAggregateRoot<TKey>
    {
        /// <summary>
        /// 批量插入实体（高性能）
        /// </summary>
        Task BulkInsertAsync(IEnumerable<TDocument> entities, bool autoSave = false, CancellationToken cancellationToken = default);

        /// <summary>
        /// 批量更新实体（高性能）
        /// </summary>
        Task BulkUpdateAsync(IEnumerable<TDocument> entities, bool autoSave = false, CancellationToken cancellationToken = default);

        /// <summary>
        /// 批量删除实体（高性能）
        /// </summary>
        Task BulkDeleteAsync(IEnumerable<TDocument> entities, bool autoSave = false, CancellationToken cancellationToken = default);

        Task<List<TDocument>> GetPagedListAsync(
            string filter,
            int skipCount = int.MaxValue,
            int maxResultCount = 0,
            string sorting = null,
            bool includeDetails = false,
            CancellationToken cancellationToken = default);

        Task<List<TDocument>> GetPagedListAsync(
            Expression<Func<TDocument, bool>> predicate,
            int skipCount = int.MaxValue,
            int maxResultCount = 0,
            string sorting = null,
            bool includeDetails = false,
            CancellationToken cancellationToken = default);

        Task<long> GetCountAsync(bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<long> GetCountAsync(string filter, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<long> GetCountAsync(Expression<Func<TDocument, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<TDocumentLine> FindChildAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);

        Task<TDocumentLine> GetChildAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);

        Task<List<TDocumentLine>> GetChildrenPagedListAsync(
            Expression<Func<TDocumentLine, bool>> predicate,
            int skipCount = int.MaxValue,
            int maxResultCount = 0,
            string sorting = null,
            bool includeDetails = false,
            CancellationToken cancellationToken = default);

        Task<long> GetChildrenCountAsync(bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<long> GetChildrenCountAsync(Expression<Func<TDocumentLine, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default);
    }

    public interface IDocumentRepository<TDocument, TDocumentLine> : IDocumentRepository<TDocument, TDocumentLine, Guid>
        where TDocument : class, IDocumentAggregateRoot<TDocumentLine, Guid>
        where TDocumentLine : class, IDocumentLineAggregateRoot<Guid>
    {

    }
}
